import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class AlienLanguage {
	private static class Tree {
		Tree sub[] = new Tree[26];
		private Tree insert(char c) {
			if(sub[c - 'a'] == null)
				sub[c - 'a'] = new Tree();
			return sub[c - 'a'];
		}
		public void insert(String s) {
			Tree t = this;
			char[] chars = s.toCharArray();
			for(char c : chars)
				t = t.insert(c);
		}
	}
	private static int comb(List<Character>[] tokens, Tree t, String poss) {
		if(t == null)
			return 0;
		if(poss.length() >= tokens.length)
			return 1;
		int comb = 0;
		for(int i = 0; i < tokens[poss.length()].size(); i++)
			comb += comb(tokens, t.sub[tokens[poss.length()].get(i) - 'a'], poss + tokens[poss.length()].get(i));
		return comb;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
		try {
			String[] LDN = rdr.readLine().split(" ");
			int L = Integer.parseInt(LDN[0]);
			int D = Integer.parseInt(LDN[1]);
			int N = Integer.parseInt(LDN[2]);
			Tree t = new Tree();
			for(int d = 0; d < D; d++)
				t.insert(rdr.readLine());
			for(int n = 1; n <= N; n++) {
				String s = rdr.readLine();
				List<Character>[] tokens = new List[L];
				char[] chars = s.toCharArray();
				int i = -1;
				boolean open = false;
				for(char c : chars) {
					if(!open)
						i++;
					if(c == '(') {
						open = true;
						continue;
					} else if(c == ')') {
						open = false;
						continue;
					}
					if(tokens[i] == null)
						tokens[i] = new ArrayList<Character>();
					tokens[i].add(c);
				}
				System.out.println("Case #" + n + ": " + comb(tokens, t, ""));
			}
		} finally {
			rdr.close();
		}
	}
}
